﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:v="clr-namespace:ShredTheLog.Views;assembly=ShredTheLog.Views"
    xmlns:vm="clr-namespace:ShredTheLog.ViewModels;assembly=ShredTheLog.ViewModels"
    xmlns:cnv="clr-namespace:ShredTheLog.Converters;assembly=ShredTheLog.Converters"
    xmlns:c="clr-namespace:ShredTheLog.Controls;assembly=ShredTheLog.Controls"
    >

    <DataTemplate DataType="{x:Type vm:LogInViewModel}">
        <DataTemplate.Resources>
            <Thickness x:Key="ButtonMargin" Left="{x:Static c:UX.ButtonSeparatorWidth}" Top="{x:Static c:UX.DialogPadding}"/>
        </DataTemplate.Resources>

        <Grid x:Name="grid" Margin="{x:Static c:UX.DialogPaddingThickness}">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
                
            <Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Label Grid.Row="0" Grid.Column="0" Content="{c:LocalizedString s_Label_Username}" VerticalAlignment="Center" Target="userName"/>
                <TextBox x:Name="userName" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding Path=InitialUserName, Mode=OneTime}"/>
                <Label Grid.Row="1" Grid.Column="0" Content="{c:LocalizedString s_Label_Password}" VerticalAlignment="Center" Target="password"/>
                <PasswordBox x:Name="password" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" c:Extensions.Password="{Binding Path=InitialPassword, Mode=OneTime}"/>
                <CheckBox x:Name="rememberPassword" Grid.Row="2" Grid.ColumnSpan="2" Content="{c:LocalizedString s_RememberPassword}" IsChecked="{Binding Path=InitialRememberPassword, Mode=OneTime}" HorizontalAlignment="Left"/>
            </Grid>
                
            <Button Grid.Row="1" Grid.Column="1" Content="{c:LocalizedString s_OK}" IsDefault="True" Command="{Binding LogInCommand}" MinWidth="{x:Static c:UX.ButtonWidth}" Margin="{StaticResource ButtonMargin}">
                <Button.CommandParameter>
                    <MultiBinding Converter="{x:Static vm:LogInCommandParameterConverter.Default}">
                        <Binding ElementName="userName" Path="Text" Mode="OneWay"/>
                        <Binding ElementName="password" Path="(c:Extensions.Password)" Mode="OneWay"/>
                        <Binding ElementName="rememberPassword" Path="IsChecked" Mode="OneWay"/>
                    </MultiBinding>
                </Button.CommandParameter>
            </Button>
            <Button Grid.Row="1" Grid.Column="2" Content="{c:LocalizedString s_Cancel}" IsCancel="True" Command="{Binding CloseCommand}" MinWidth="{x:Static c:UX.ButtonWidth}" Margin="{StaticResource ButtonMargin}"/>
        </Grid>

        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsLoggingIn}" Value="true">
                <Setter TargetName="grid" Property="Cursor" Value="Wait"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>